﻿
''' <summary>
''' 維修信息
''' </summary>
''' <remarks>
''' Create Data:2008-04-24
''' Create Person:huyang
''' </remarks>
Public Class Frm_CSMainTain

    Implements IDServer.IDServer.IDServer


#Region "Variabled"

#Region "System Variabled Define"


    Public ActionHelp As IDServer.IDServer.ActionBtn = IDServer.IDServer.ActionBtn.ActionHelp

    Private WithEvents MainForm As Frm_MainForm

    Public Property SelectObject() As Frm_MainForm
        Get
            Return MainForm
        End Get
        Set(ByVal value As Frm_MainForm)
            MainForm = value
        End Set
    End Property

    Public action_help As IDServer.IDServer.ActionBtn = IDServer.IDServer.ActionBtn.ActionHelp

#End Region

#Region "user variabled define"

    ''' <summary>
    ''' 窗體是否加載
    ''' </summary>
    ''' <remarks></remarks>
    Private fLoadBool As Boolean = False

    Private Fields As String

    Public FindBool As Boolean = True


#End Region

#End Region

#Region "Methods"

#Region "ExecFind"

    Private Function ReturnWhereExp()
        Dim sql As String = ""

        If Me.fLoadBool = False Then
            sql &= "  where 1<>1 "
        Else
            sql &= " where 1=1"
            If Me.txt_ProxyCode.Text.Trim <> "" Then
                sql &= "   and  ProxyCode='" & Replace_Text(Me.txt_ProxyCode.Text.Trim) & "'"
            End If
            If Me.txt_ShortCode.Text.Trim <> "" Then
                sql &= "  and ShortCode like '%" & Replace_Text(Me.txt_ShortCode.Text.Trim) & "%'"
            End If
            If Me.txt_ProxyName.Text.Trim <> "" Then
                sql &= "  and ProxyName like '%" & Replace_Text(Me.txt_ProxyName.Text.Trim) & "%'"
            End If
            If Me.txt_GoodsName.Text.Trim <> "" Then
                sql &= "  and GoodsName like '%" & Replace_Text(Me.txt_GoodsName.Text.Trim) & "%'"
            End If
            If Me.txt_GoodsCode.Text.Trim <> "" Then
                sql &= "  and GoodsCode like '%" & Replace_Text(Me.txt_GoodsCode.Text.Trim) & "%'"
            End If

            If Me.TextBox1.Text.Trim <> "" Then
                sql &= "  and (ShortCode like '%" & Replace_Text(Me.TextBox1.Text.Trim) & "%'   or ProxyName like '%" & Replace_Text(Me.TextBox1.Text) & "%'  or ProxyEnname like '" & Replace_Text(Me.TextBox1.Text) & "'   or  GoodsName like '%" & Replace_Text(Me.TextBox1.Text.Trim) & "%'   "
                sql &= "  or GoodsCode like '%" & Replace_Text(Me.TextBox1.Text) & "%'   or Telphone like '%" & Replace_Text(Me.TextBox1.Text.Trim) & "%' or Fax like '%" & Replace_Text(Me.TextBox1.Text.Trim) & "%'  or httpURL like '%" & Replace_Text(Me.TextBox1.Text) & "%'   or Remark like '%" & Me.TextBox1.Text.Trim & "%'  or Address like '%" & Me.TextBox1.Text.Trim & "%')"

            End If

        End If
        Return sql
    End Function

    Private Sub ExecFind()

        Me.Cursor = Cursors.WaitCursor
        Dim whereExp As String = Me.ReturnWhereExp()

        Dim sql As String = "  select * from CS_MainTain " & whereExp & vbCrLf

        Try

            Dim Dtab As New DataTable

            Dtab = Exec(sql, E_ExecType.DataTable)

            Me.DGV_Master.DataSource = Dtab

            BindDataGridViewCaption(Me.DGV_Master, Me.ReturnCaption())
            FullFormatDataGridView(Me.DGV_Master, False, False)
            Me.DGV_Master.SelectionMode = DataGridViewSelectionMode.CellSelect

            DGV_Master.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells
            Dim isFind As Boolean = Me.DGV_Master.RowCount > 0

            If Me.fLoadBool = True AndAlso FindBool = True Then
                Me.SetButton(ButtonType.Browse, isFind)
            End If

        Catch ex As Exception
            MessageBox.Show(ex.Message & ex.StackTrace, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Function ReturnCaption() As Hashtable
        Dim Hash As New Hashtable
        Hash.Add("ProxyCode", "編號")
        Hash.Add("ShortCode", "代號")
        Hash.Add("ProxyName", "代理行名稱")
        Hash.Add("ProxyEnname", "英文名稱")
        Hash.Add("GoodsName", "品牌")
        Hash.Add("GoodsCode", "貨品編號")
        Hash.Add("Telphone", "電話")
        Hash.Add("Fax", "傳真")
        Hash.Add("httpURL", "網址")
        Hash.Add("Address", "地址")
        Hash.Add("Remark", "備注")
        Return Hash
    End Function

#End Region

#Region "SetEnabled"


    ''' <summary>
    ''' 設置按鈕狀態
    ''' </summary>
    ''' <param name="type">操作類型</param>
    ''' <param name="IsFind">是否是流覽</param>
    ''' <remarks></remarks>
    Private Sub SetButton(ByVal type As ButtonType, ByVal IsFind As Boolean)
        Try

            Select Case type
                Case ButtonType.Add
                    With MainForm
                        .ToolStripAdd.Enabled = False
                        .ToolStripEdit.Enabled = False
                        .ToolStripDelete.Enabled = False
                        .ToolStripSave.Enabled = True
                        .ToolStripCancel.Enabled = True
                        .ToolStripFirst.Enabled = False
                        .ToolStripLast.Enabled = False
                        .ToolStripNext.Enabled = False
                        .ToolStripPrivous.Enabled = False
                        .ToolStripExport.Enabled = IsFind
                        .ToolStripImport.Enabled = True
                        .ToolStripPrint.Enabled = IsFind
                        .ToolStripFilter.Enabled = True

                    End With

                Case ButtonType.Browse
                    With MainForm
                        .ToolStripAdd.Enabled = True
                        .ToolStripEdit.Enabled = IsFind
                        .ToolStripDelete.Enabled = IsFind
                        .ToolStripSave.Enabled = False
                        .ToolStripCancel.Enabled = False
                        .ToolStripFirst.Enabled = IsFind
                        .ToolStripLast.Enabled = IsFind
                        .ToolStripNext.Enabled = IsFind
                        .ToolStripPrivous.Enabled = IsFind
                        .ToolStripExport.Enabled = IsFind
                        .ToolStripImport.Enabled = True
                        .ToolStripPrint.Enabled = IsFind
                        .ToolStripFilter.Enabled = True
                        .ToolStripCheck.Enabled = False
                        .ToolStripComplete.Enabled = False
                        .ToolStripUnCheck.Enabled = False
                    End With

                Case ButtonType.Cancel
                    With MainForm
                        .ToolStripAdd.Enabled = True
                        .ToolStripEdit.Enabled = IsFind
                        .ToolStripDelete.Enabled = IsFind
                        .ToolStripSave.Enabled = False
                        .ToolStripCancel.Enabled = False
                        .ToolStripFirst.Enabled = IsFind
                        .ToolStripLast.Enabled = IsFind
                        .ToolStripNext.Enabled = IsFind
                        .ToolStripPrivous.Enabled = IsFind
                        .ToolStripExport.Enabled = IsFind
                        .ToolStripImport.Enabled = True
                        .ToolStripPrint.Enabled = IsFind
                        .ToolStripFilter.Enabled = True

                    End With

                Case ButtonType.Edit
                    With MainForm
                        .ToolStripAdd.Enabled = False
                        .ToolStripEdit.Enabled = False
                        .ToolStripDelete.Enabled = False
                        .ToolStripSave.Enabled = True
                        .ToolStripCancel.Enabled = True
                        .ToolStripFirst.Enabled = False
                        .ToolStripLast.Enabled = False
                        .ToolStripNext.Enabled = False
                        .ToolStripPrivous.Enabled = False
                        .ToolStripExport.Enabled = IsFind
                        .ToolStripImport.Enabled = True
                        .ToolStripPrint.Enabled = IsFind
                        .ToolStripFilter.Enabled = True

                    End With

            End Select
        Catch ex As Exception
            MsgBox(ex.ToString, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, Msg.CompanyName)
        End Try

    End Sub



#End Region

#Region "AddHandler Events"

    ''' <summary>
    ''' KeyDown Event
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub TextBox_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)
        Try
            Select Case e.KeyCode
                Case Keys.Enter
                    If e.Shift = True Then
                        If TypeOf sender Is ComboBox Then
                            If CType(sender, ComboBox).DroppedDown = True Then
                                CType(sender, ComboBox).DroppedDown = False
                            End If
                        End If
                        Me.ProcessTabKey(False)
                        SendKeys.Send("{F4}")
                    Else
                        If TypeOf sender Is ComboBox Then
                            If CType(sender, ComboBox).DroppedDown = True Then
                                CType(sender, ComboBox).DroppedDown = False
                            End If
                        End If

                        Me.ProcessTabKey(True)
                        SendKeys.Send("{F4}")

                    End If
            End Select
        Catch ex As Exception
            MsgBox("TextBox_KeyDown:" & ex.Message & ex.StackTrace, MsgBoxStyle.Critical And MsgBoxStyle.OkOnly, Msg.CompanyName)
        End Try
    End Sub

    ''' <summary>
    ''' 添加自定義事件
    ''' </summary>
    ''' <param name="Pans"></param>
    ''' <remarks></remarks>
    Private Sub AddHandlers(ByVal Pans() As Control)
        Try
            For Each Pan As Control In Pans
                For Each Ctrl As Control In Pan.Controls
                    If TypeOf Ctrl Is TextBox _
                       OrElse TypeOf Ctrl Is ComboBox _
                       OrElse TypeOf Ctrl Is DateTimePicker Then
                        AddHandler Ctrl.KeyDown, AddressOf TextBox_KeyDown
                    End If
                Next
            Next
        Catch ex As Exception
            MsgBox("AddHandlers:" & ex.Message & ex.StackTrace, MsgBoxStyle.Critical And MsgBoxStyle.OkOnly, Msg.CompanyName)
        End Try
    End Sub

#End Region

#Region "FillDetail"

    Private Sub FillDetail(ByVal ProxyCode As String)
        Try
            Dim Dtab As DataTable = DirectCast(Me.DGV_Master.DataSource, DataTable)
            Dim DRow() As DataRow = Dtab.Select("ProxyCode='" & ProxyCode & "'")

            If DRow.Length > 0 Then

                Me.txtProxyCode.Text = DRow(0).Item("ProxyCode") & ""
                Me.txtShortCode.Text = DRow(0).Item("ShortCode") & ""
                Me.txtProxyName.Text = DRow(0).Item("ProxyName") & ""
                Me.txtProxyEnname.Text = DRow(0).Item("ProxyEnname") & ""
                Me.txtGoodsName.Text = DRow(0).Item("GoodsName") & ""
                Me.txtGoodsCode.Text = DRow(0).Item("GoodsCode") & ""
                Me.txtTelphone.Text = DRow(0).Item("Telphone") & ""
                Me.txtFax.Text = DRow(0).Item("Fax") & ""
                Me.txthttpURL.Text = DRow(0).Item("httpURL") & ""
                Me.txtAddress.Text = DRow(0).Item("Address") & ""
                Me.txtRemark.Text = DRow(0).Item("Remark") & ""
            Else
                Me.txtProxyCode.Text = ""
                Me.txtShortCode.Text = ""
                Me.txtProxyName.Text = ""
                Me.txtProxyEnname.Text = ""
                Me.txtGoodsName.Text = ""
                Me.txtGoodsCode.Text = ""
                Me.txtTelphone.Text = ""
                Me.txtFax.Text = ""
                Me.txthttpURL.Text = ""
                Me.txtAddress.Text = ""
                Me.txtRemark.Text = ""

            End If

        Catch ex As Exception
            MessageBox.Show(ex.Message & ex.StackTrace, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub

#End Region

#Region "SaveData"

    Private Function Validated1() As Boolean
        If Me.txtGoodsName.Text.Trim = "" Then
            MessageBox.Show("代理品牌不能為空。", Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Warning)
            Me.txtGoodsName.Focus()
            Return False
        End If
        Return True
    End Function

    Private Function SaveData() As Boolean
        Dim bSuccess As Boolean = False

        Dim ProxyCode As String = Me.txtProxyCode.Text.Trim
        Dim ShortCode As String = Me.txtShortCode.Text.Trim
        Dim ProxyName As String = Me.txtProxyName.Text.Trim
        Dim ProxyEnname As String = Me.txtProxyEnname.Text.Trim
        Dim GoodsName As String = Me.txtGoodsName.Text.Trim
        Dim GoodsCode As String = Me.txtGoodsCode.Text.Trim
        Dim Telphone As String = Me.txtTelphone.Text.Trim
        Dim Fax As String = Me.txtFax.Text.Trim
        Dim httpURL As String = Me.txthttpURL.Text.Trim
        Dim Address As String = Me.txtAddress.Text.Trim
        Dim Remark As String = Me.txtRemark.Text.Trim

        Dim sql As New System.Text.StringBuilder()

        If ActionHelp = IDServer.IDServer.ActionBtn.ActionAdd Then

            ProxyCode = Exec("select Isnull(Max(ProxyCode),0) from CS_MainTain", E_ExecType.ExecuteScalar) & ""
            ProxyCode = (Val(ProxyCode) + 1).ToString("00000")
            Me.txtProxyCode.Text = ProxyCode

            sql.Append("Insert Into CS_MainTain(" & vbCrLf)
            sql.Append("ProxyCode,ShortCode,ProxyName,ProxyEnname,GoodsName,")
            sql.Append("GoodsCode,Telphone,Fax,httpURL,Address,Remark)" & vbCrLf)
            sql.Append("values(" & vbCrLf)
            sql.Append("'" & ProxyCode & "','" & ShortCode & "','" & ProxyName & "','" & ProxyEnname & "','" & GoodsName & "',")
            sql.Append("'" & GoodsCode & "','" & Telphone & "','" & Fax & "','" & httpURL & "','" & Address & "','" & Remark & "'")
            sql.Append(")" & vbCrLf)

        Else

            sql.Append("UPDATE [Test].[dbo].[CS_MainTain]" & vbCrLf)
            sql.Append("                SET ")
            sql.Append("                 [ShortCode] = '" & ShortCode & "'")
            sql.Append("                ,[ProxyName] = '" & ProxyName & "'")
            sql.Append("                ,[ProxyEnname] = '" & ProxyEnname & "'")
            sql.Append("                ,[GoodsName] = '" & GoodsName & "'")
            sql.Append("                ,[GoodsCode] = '" & GoodsCode & "'")
            sql.Append("                ,[Telphone] = '" & Telphone & "'")
            sql.Append("                ,[Fax] = '" & Fax & "'")
            sql.Append("                ,[httpURL] = '" & httpURL & "'")
            sql.Append("                ,[Address] = '" & Address & "'")
            sql.Append("                ,[Remark] = '" & Remark & "'")
            sql.Append("                WHERE ProxyCode='" & ProxyCode & "'")

        End If

        Try
            Exec(sql.ToString(), E_ExecType.ExecuteNonQuery, True)
            UpdateData(ProxyCode, ShortCode, ProxyName, ProxyEnname, GoodsName, _
            GoodsCode, Telphone, Fax, httpURL, Address, Remark)
            bSuccess = True
        Catch ex As Exception
            bSuccess = False
            MessageBox.Show(IIf(ActionHelp = IDServer.IDServer.ActionBtn.ActionAdd, My.Resources.ErrAdd, My.resources.ErrEdit), Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
        If bSuccess = True Then
            MessageBox.Show(IIf(ActionHelp = IDServer.IDServer.ActionBtn.ActionAdd, My.Resources.AddSuccess, My.resources.EditSuccess), Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Information)
        End If
        Dim cs As setControlEnabled = New setControlEnabled(New Control() {Me.GroupBox2})
        cs.SetControlsEnabled(False)
        ActionHelp = IDServer.IDServer.ActionBtn.ActionHelp
        Me.SetButton(ButtonType.Browse, True)
        Me.txtGoodsName.BackColor = System.Drawing.SystemColors.Control
        Return bSuccess
    End Function

    Private Function UpdateData(ByVal ProxyCode As String, ByVal ShortCode As String, ByVal ProxyName As String, ByVal ProxyEnname As String, ByVal GoodsName As String, _
                                                    ByVal GoodsCode As String, ByVal Telphone As String, ByVal Fax As String, ByVal httpURL As String, ByVal Address As String, ByVal Remark As String)

        Dim bSuccess As Boolean = False

        Dim Dtab As DataTable = DirectCast(Me.DGV_Master.DataSource, DataTable)

        If ActionHelp = IDServer.IDServer.ActionBtn.ActionAdd Then
            Dim Row As DataRow = Dtab.NewRow()

            Row("ProxyCode") = ProxyCode
            Row("ShortCode") = ShortCode
            Row("ProxyName") = ProxyName
            Row("ProxyEnname") = ProxyEnname
            Row("GoodsName") = GoodsName
            Row("GoodsCode") = GoodsCode
            Row("Telphone") = Telphone
            Row("Fax") = Fax
            Row("httpURL") = httpURL
            Row("Address") = Address
            Row("Remark") = Remark

            Dtab.Rows.Add(Row)
        Else

            Dim DRow() As DataRow = Dtab.Select("ProxyCode='" & ProxyCode & "'")

            If DRow.Length > 0 Then
                Dim Row As DataRow = DRow(0)
                Row("ShortCode") = ShortCode
                Row("ProxyName") = ProxyName
                Row("ProxyEnname") = ProxyEnname
                Row("GoodsName") = GoodsName
                Row("GoodsCode") = GoodsCode
                Row("Telphone") = Telphone
                Row("Fax") = Fax
                Row("httpURL") = httpURL
                Row("Address") = Address
                Row("Remark") = Remark
            End If

        End If
        Dtab.AcceptChanges()

        Me.DGV_Master.Update()
        Me.DGV_Master.Refresh()
        bSuccess = True

        Return bSuccess
    End Function

#End Region

#End Region

#Region "Events"

#Region "Load Form"

    Private Sub Frm_CSMainTain_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Me.fLoadBool = False
        AddHandlers(New Control() {Me.Panel1, Me.Panel2, Me.GroupBox2})
        addColtrolEvents()
        Dim cs As setControlEnabled = New setControlEnabled(New Control() {Me.GroupBox2})
        cs.SetControlsEnabled(False)
        Dim imeMode As clsIme = New clsIme()
        imeMode.AddHandler_ImeMode(New Control() {Me.Panel1, Me.GroupBox2})
        ExecFind()
        SetGridCaptionVisible(Me.DGV_Master, Fields, "Frm_CSMainTain")
        Me.fLoadBool = True
    End Sub

#End Region

#Region "Button"

    Private Sub btnFind_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnFind.Click
        Me.ExecFind()
    End Sub

#End Region

#Region "TabControl"

    Private Sub TabControl1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TabControl1.KeyDown
        Select Case e.KeyCode
            Case Keys.S
                If e.Control = True Then
                    If (ActionHelp = IDServer.IDServer.ActionBtn.ActionAdd OrElse ActionHelp = IDServer.IDServer.ActionBtn.ActionEdit) Then
                        MainForm.ToolStripSave.PerformClick()
                    End If
                End If
        End Select
    End Sub

    Private Sub TabControl1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TabControl1.SelectedIndexChanged
        If Me.TabControl1.SelectedIndex = 1 Then
            Dim ProxyCode As String = ""
            If Not Me.DGV_Master.CurrentRow Is Nothing Then
                ProxyCode = Me.DGV_Master.CurrentRow.Cells("ProxyCode").Value & ""
            End If
            FillDetail(ProxyCode)
        End If
    End Sub

    Private Sub TabControl1_Selecting(ByVal sender As Object, ByVal e As System.Windows.Forms.TabControlCancelEventArgs) Handles TabControl1.Selecting
        If ActionHelp = IDServer.IDServer.ActionBtn.ActionAdd OrElse ActionHelp = IDServer.IDServer.ActionBtn.ActionEdit Then
            e.Cancel = True
        End If
    End Sub



#End Region

#Region "DataGridView"

    Private Sub DGV_Master_CellDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DGV_Master.CellDoubleClick
        Me.TabControl1.SelectedIndex = 1
    End Sub

#End Region


#End Region

#Region "Interface"

    Public Function ActionAdd() As Boolean Implements IDServer.IDServer.IDServer.ActionAdd
        Try
            If AddEnable = False Then
                MessageBox.Show("對不起，您沒有新增權限", Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Information)
                Exit Function
            End If


            If Me.TabControl1.SelectedIndex = 0 Then
                Me.TabControl1.SelectedIndex = 1
            End If
            Me.FillDetail("")
            ActionHelp = IDServer.IDServer.ActionBtn.ActionAdd
            Me.SetButton(ButtonType.Add, False)
            Dim cs As setControlEnabled = New setControlEnabled(New Control() {Me.GroupBox2})
            cs.SetControlsEnabled(True)
            Me.txtProxyCode.ReadOnly = True
            Me.txtGoodsName.BackColor = System.Drawing.SystemColors.ActiveCaptionText
            Me.txtShortCode.Focus()
            Return True
        Catch ex As Exception
            MessageBox.Show(ex.Message & ex.StackTrace, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Function

    Public Function ActionCancel() As Boolean Implements IDServer.IDServer.IDServer.ActionCancel
        Try
            Dim ProxyCode As String = ""
            Dim IsFind As Boolean = False
            If Not Me.DGV_Master.CurrentRow Is Nothing Then
                ProxyCode = Me.DGV_Master.CurrentRow.Cells("ProxyCode").Value & ""
                IsFind = True
            End If
            Me.FillDetail(ProxyCode)
            Dim cs As setControlEnabled = New setControlEnabled(New Control() {Me.GroupBox2})
            cs.SetControlsEnabled(False)
            Me.txtGoodsName.BackColor = System.Drawing.SystemColors.Control
            ActionHelp = IDServer.IDServer.ActionBtn.ActionHelp
            Me.SetButton(ButtonType.Browse, IsFind)
            Return True
        Catch ex As Exception
            MessageBox.Show(ex.Message & ex.StackTrace, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Function

    Public Function ActionDelete() As Boolean Implements IDServer.IDServer.IDServer.ActionDelete
        Try
            If DeleteEnable = False Then
                MessageBox.Show("對不起，您沒有刪除權限", Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Information)
                Exit Function
            End If

            If Me.DGV_Master.CurrentRow Is Nothing Then Return False

            If MessageBox.Show(My.Resources.ConfirmDelete, Msg.CompanyName, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) <> DialogResult.OK Then Return False

            Dim ProxyCode As String = Me.DGV_Master.CurrentRow.Cells("ProxyCode").Value & ""

            Dim Dtab As DataTable = DirectCast(Me.DGV_Master.DataSource, DataTable)

            Dim DRow() As DataRow = Dtab.Select("ProxyCode='" & ProxyCode & "'")
            If DRow.Length > 0 Then
                DRow(0).Delete()
            End If
            Dtab.AcceptChanges()

            Dim sql As String = " delete CS_MainTain where ProxyCode='" & ProxyCode & "'  "

            Exec(sql, E_ExecType.ExecuteNonQuery)

            MessageBox.Show(My.resources.DeleteSuccess, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Information)

            Dim IsFind As Boolean = False
            If Not Me.DGV_Master.CurrentRow Is Nothing Then
                ProxyCode = Me.DGV_Master.CurrentRow.Cells("ProxyCode").Value & ""
                IsFind = True
            End If

            Me.FillDetail(ProxyCode)
            Me.SetButton(ButtonType.Browse, IsFind)

            Return True
        Catch ex As Exception
            MessageBox.Show(My.resources.ErrDelete, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Function

    Public Function ActionEdit() As Boolean Implements IDServer.IDServer.IDServer.ActionEdit
        Try
            If EditEnable = False Then
                MessageBox.Show("對不起，您沒有修改權限", Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Information)
                Exit Function
            End If

            If Me.TabControl1.SelectedIndex = 0 Then
                Me.TabControl1.SelectedIndex = 1
            End If
            ActionHelp = IDServer.IDServer.ActionBtn.ActionEdit
            Me.SetButton(ButtonType.Edit, False)
            Dim cs As setControlEnabled = New setControlEnabled(New Control() {Me.GroupBox2})
            cs.SetControlsEnabled(True)
            Me.txtGoodsName.BackColor = System.Drawing.SystemColors.ActiveCaptionText
            Me.txtProxyCode.ReadOnly = True
            Me.txtProxyName.Focus()
            Return True
        Catch ex As Exception
            MessageBox.Show(ex.Message & ex.StackTrace, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Function

    Public Function ActionExport() As Boolean Implements IDServer.IDServer.IDServer.ActionExport

    End Function

    Public Function ActionFilter() As Boolean Implements IDServer.IDServer.IDServer.ActionFilter
        Try
            Dim Frm_Filter As New Frm_Filter
            Me.Cursor = Cursors.WaitCursor
            Frm_Filter.LoadHeaderCaption(Fields, "Frm_CSMainTain")
            Frm_Filter.ShowDialog()
            Me.Cursor = Cursors.Default
            ReBindGridCaption(Me.DGV_Master, "Frm_CSMainTain")
        Catch ex As Exception
            MsgBox("ActionFilter:" + ex.ToString, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, Msg.CompanyName)
        End Try
    End Function

    Public Function ActionGoFirst() As Boolean Implements IDServer.IDServer.IDServer.ActionGoFirst

    End Function

    Public Function ActionGoLast() As Boolean Implements IDServer.IDServer.IDServer.ActionGoLast

    End Function

    Public Function ActionGoNext() As Boolean Implements IDServer.IDServer.IDServer.ActionGoNext

    End Function

    Public Function ActionGoPrevious() As Boolean Implements IDServer.IDServer.IDServer.ActionGoPrevious

    End Function

    Public Function ActionImport() As Boolean Implements IDServer.IDServer.IDServer.ActionImport

    End Function

    Public Function ActionInitialize() As Boolean Implements IDServer.IDServer.IDServer.ActionInitialize

    End Function

    Public Function ActionPrint() As Boolean Implements IDServer.IDServer.IDServer.ActionPrint

    End Function

    Public Function ActionSave() As Boolean Implements IDServer.IDServer.IDServer.ActionSave
        If Me.Validated1() = False Then Return False

        Dim bSuccess As Boolean = SaveData()

        Return bSuccess
    End Function

    Public Function ActionSelect() As Boolean Implements IDServer.IDServer.IDServer.ActionSelect

    End Function

#End Region

    Private Sub Label7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label7.Click

    End Sub
    Private Sub txtProxyEnname_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtProxyEnname.TextChanged

    End Sub
    Private Sub Label8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label8.Click

    End Sub
    Private Sub txtShortCode_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtShortCode.TextChanged

    End Sub
    Private Sub Label9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label9.Click

    End Sub
    Private Sub txtProxyName_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtProxyName.TextChanged

    End Sub
    Private Sub Label10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label10.Click

    End Sub
    Private Sub txtProxyCode_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtProxyCode.TextChanged

    End Sub

    Private Sub addColtrolEvents()

        For Each col As Control In Me.GroupBox1.Controls
            If TypeOf col Is TextBox OrElse TypeOf col Is ComboBox Then
                AddHandler col.KeyDown, AddressOf col_KeyDown
            End If
        Next
    End Sub

    Private Sub col_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs)
        If e.KeyCode = Keys.Enter Then
            Me.btnFind.PerformClick()
        End If
    End Sub

End Class
